import {useState,useRef} from 'react'

function Sub(props){
    return (
        <>
            <h2>子组件的数字：{props.num}</h2>
            <button onClick={()=>props.childFn(2)}>累加</button>
        </>
    )
}
export default function UseRef() {
    const [num,setNum]=useState(1)

    // const element = useRef(null)

    const childFn =(plus)=> setNum(num+plus)
    
  return (
    <div>
       <Sub num={num} childFn={childFn} />
        {/* <button onClick={()=>setNum(num+1)}>累加</button> */}
    </div>
  )
}
